package sng.modules.view.components.city.logic.movement
{
	import sng.modules.view.components.city.logic.event.TileEvent;
	import sng.modules.view.components.city.logic.unit.MoveChar;
	import sng.modules.view.components.city.logic.unit.Tile;

	/**
	 * 移动处理逻辑基类
	 * 
	 */
	public class TileMovement
	{
		protected var _tile:MoveChar;

		public function TileMovement()
		{

		}

		public function execute(params:Array = null):void
		{
			
		}
		
		public function abort():void {
			
		}

		protected function complete(... args):void
		{
			tile.dispatchEvent(new TileEvent(TileEvent.MOVE_COMPLETE));
		}

		/**
		 * The direction the tile should face
		 */
		protected function getFaceDirection(x:Number, y:Number):String
		{

			if (x == tile.x && y > tile.y)
			{
				return Directions.S;
			}
			else if (x == tile.x && y < tile.y)
			{
				return Directions.N;
			}
			else if (x < tile.x && y == tile.y)
			{
				return Directions.W;
			}
			else if (x > tile.x && y == tile.y)
			{
				return Directions.E;
			}
			return tile.faceDirection;
		}

		public function get tile():MoveChar { return _tile; }
		
		public function set tile(value:MoveChar):void 
		{
			_tile = value;
		}
		
	}

}